package com.ajie.utils;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;


/**
 * 统一返回结果
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "响应参数")
@Slf4j
public class Result {
    
    /**
     * 响应给前端是否成功
     */
    @ApiModelProperty(value = "响应给前端是否成功",dataType = "boolean")
    private boolean flag;


    /**
     * 响应信息
     */
    @ApiModelProperty(value = "响应信息",dataType = "String")
    private String message;

    /**
     * 响应数据
     */
    @ApiModelProperty(value = "响应数据",dataType = "Object")
    private Object data;



    public Result(boolean flag, String message) {
        this.flag = flag;
        this.message = message;
    }

    /**
     * 响应成功
     * @param message
     * @param data
     * @return
     */
    public static Result success(String message, Object data){
        log.info("该文件名是：Result,该方法是：success");
        return new Result(true,message,data);
    }

    /**
     * 响应成功结果
     * @param message
     * @return
     */
    public static Result success(String message){
        log.info("该文件名是：Result,该方法是：success");
        return new Result(true,message);
    }
    /**
     * 响应失败
     */

    public static Result fail(String message){
        log.info("该文件名是：Result,该方法是：fail");
        return new Result(false,message);
    }
}
